package com.struts.upload.app;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<File> ppt;
	private List<String> pptContentType;
	private List<String> pptFileName;
	private List<String> pptDesc;
	
	public List<File> getPpt() {
		return ppt;
	}

	public void setPpt(List<File> ppt) {
		this.ppt = ppt;
	}

	public List<String> getPptContentType() {
		return pptContentType;
	}

	public void setPptContentType(List<String> pptContentType) {
		this.pptContentType = pptContentType;
	}

	public List<String> getPptFileName() {
		return pptFileName;
	}

	public void setPptFileName(List<String> pptFileName) {
		this.pptFileName = pptFileName;
	}

	public List<String> getPptDesc() {
		return pptDesc;
	}

	public void setPptDesc(List<String> pptDesc) {
		this.pptDesc = pptDesc;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		System.out.println(ppt);
		System.out.println(pptContentType);
		System.out.println(pptFileName);
		System.out.println(pptDesc);
		
		
		
		for(int i=0;i<ppt.size();i++){
			StringBuffer buf=new StringBuffer("d://upload/" + pptFileName.get(i));
		
		    System.out.println(buf);
		    
		    FileInputStream in=new FileInputStream(ppt.get(i));
			FileOutputStream out=new FileOutputStream(buf.toString());
			
			byte[] buffer=new byte[1024];
			int len=0;
			
			while((len=in.read(buffer))!=-1){
				out.write(buffer, 0, len);
			}
			
			out.close();
			in.close();
		}
		
		return SUCCESS;
	}

}
